package com.sj.common.bean;

import cn.hutool.core.util.StrUtil;
import com.sj.common.exception.CustomException;
import com.sj.entity.User;
import com.sj.utils.JwtUtils;
import com.sj.utils.RedisUtils;
import com.sj.utils.RequestUtils;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * Created with IntelliJ IDEA.
 * User: xiaoqi
 * Date: 2022-03-10
 * Time: 下午 14:07
 * Description: 本地用户对象
 *
 * @author xiaoqi
 * @since 2022-03-10
 */
public class LocalUser {
    private static ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<>();

    public static void set(User user) {
        Map<String, Object> map = new HashMap<>();
        map.put("user", user);
        LocalUser.threadLocal.set(map);
    }

    public static User getUser() {
        Map<String, Object> map = LocalUser.threadLocal.get();
        User user = (User) map.get("user");
        return user;
    }

    public static void clear() {
        LocalUser.threadLocal.remove();
    }

}